package com.doit.day01;

import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/*
KEYIN :读取数据的一个偏移量
VALUEIN:读取的一行数据
KEYOUT:
VALUEOUT
 */
public class CreateHFileDemo extends Mapper<LongWritable, Text, ImmutableBytesWritable, KeyValue> {
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, ImmutableBytesWritable, KeyValue>.Context context) throws IOException, InterruptedException {
        //rowkey_001,zss,18,male,chengxuyuan,beijing
        String str = value.toString();

        String[] arr = str.split(",");

        //第一个传入的是rowkey
        //第二个传入的是列族
        //第三个传入的是列
        //最后传入值
        ImmutableBytesWritable immutableBytesWritable = new ImmutableBytesWritable(arr[0].getBytes());
        KeyValue keyValue = new KeyValue(arr[0].getBytes(),"f1".getBytes(),"name".getBytes(),arr[1].getBytes());
        context.write(immutableBytesWritable,keyValue);

        ImmutableBytesWritable immutableBytesWritable1 = new ImmutableBytesWritable(arr[0].getBytes());
        KeyValue keyValue1 = new KeyValue(arr[0].getBytes(),"f1".getBytes(),"age".getBytes(),arr[2].getBytes());
        context.write(immutableBytesWritable1,keyValue1);

        ImmutableBytesWritable immutableBytesWritable2 = new ImmutableBytesWritable(arr[0].getBytes());
        KeyValue keyValue2 = new KeyValue(arr[0].getBytes(),"f1".getBytes(),"gender".getBytes(),arr[3].getBytes());
        context.write(immutableBytesWritable2,keyValue2);

        ImmutableBytesWritable immutableBytesWritable3 = new ImmutableBytesWritable(arr[0].getBytes());
        KeyValue keyValue3 = new KeyValue(arr[0].getBytes(),"f2".getBytes(),"job".getBytes(),arr[4].getBytes());
        context.write(immutableBytesWritable3,keyValue3);

        ImmutableBytesWritable immutableBytesWritable4 = new ImmutableBytesWritable(arr[0].getBytes());
        KeyValue keyValue4 = new KeyValue(arr[0].getBytes(),"f2".getBytes(),"address".getBytes(),arr[5].getBytes());
        context.write(immutableBytesWritable4,keyValue4);



    }
}
